package com.example.mqtt.controller;

import com.example.mqtt.client.MqttSendClient;
import com.example.mqtt.client.MqttSubClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestController {

    @Autowired
    private MqttSendClient mqttSendClient;

    @Autowired
    private MqttSubClient mqttSubClient;

    @RequestMapping("/send")
    public String send(){
        //订阅主题
        mqttSubClient.subscribe();
        mqttSubClient.subscribe("test");
        //发送消息到主题
        mqttSendClient.publish("新消息通知1！");
        mqttSendClient.publish("新消息通知2！");
        mqttSendClient.publish("test","新消息通知test！");

        return "发送成功";
    }
}
